package duty_info

import (
	"github.com/gin-gonic/gin"
	"log"
	"tao-admin/internal/entity"
)

type DutyService struct {
	DutyManager *DutyManager
}

func NewDutyService() *DutyService {
	return &DutyService{
		DutyManager: &DutyManager{},
	}
}

func (service *DutyService) GetDutyInfos(ctx *gin.Context, project string) ([]*entity.DutyInfoEntity, int64, error) {
	condition := &SearchDutyCondition{
		Project: &project,
	}
	if key1, isExist := ctx.GetQuery("key"); isExist == true {
		condition.Key = &key1
	}
	if value1, isExist := ctx.GetQuery("value"); isExist == true {
		condition.Value = &value1
	}
	if duty, isExist := ctx.GetQuery("duty"); isExist == true {
		condition.Duty = &duty
	}
	if component, isExist := ctx.GetQuery("component"); isExist == true {
		condition.Component = &component
	}

	dutyList, total, err := service.DutyManager.SearchDutyByConditionMng(ctx, condition)
	if err != nil {
		return nil, 0, err
	}
	log.Printf("SearchDutyByConditionMng, dutyList: %v, total: %v", &dutyList, total)
	for i, v := range dutyList {
		log.Printf("查询结果第%v个, 数据: %v", i, v)
	}
	return dutyList, total, nil
}
